<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en" class="no-js">
<!--<![endif]-->

<head>
<meta charset="utf-8">
<title>SMM撮合系统</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta content="width=device-width, initial-scale=1" name="viewport">
<meta content="" name="description">
<meta content="" name="author">
<script>
	BASE_URL = '${request.getContextPath()}'
</script>
<link href="${request.getContextPath()}/Public/assets/admin/css/css.css"
	rel="stylesheet" type="text/css">
<link
	href="${request.getContextPath()}/Public/assets/global/plugins/font-awesome/css/font-awesome.min.css"
	rel="stylesheet" type="text/css">
<link
	href="${request.getContextPath()}/Public/assets/global/plugins/simple-line-icons/simple-line-icons.min.css"
	rel="stylesheet" type="text/css">
<link
	href="${request.getContextPath()}/Public/assets/global/plugins/bootstrap/css/bootstrap.min.css"
	rel="stylesheet" type="text/css">
<link
	href="${request.getContextPath()}/Public/assets/global/plugins/uniform/css/uniform.default.css"
	rel="stylesheet" type="text/css">

<link
	href="${request.getContextPath()}/Public/assets/global/css/components-rounded.css"
	id="style_components" rel="stylesheet" type="text/css">
<link
	href="${request.getContextPath()}/Public/assets/global/css/plugins.css"
	rel="stylesheet" type="text/css">
<link
	href="${request.getContextPath()}/Public/assets/admin/css/layout.css"
	rel="stylesheet" type="text/css">
<link
	href="${request.getContextPath()}/Public/assets/admin/css/themes/default.css"
	rel="stylesheet" type="text/css" id="style_color">
<link
	href="${request.getContextPath()}/Public/assets/admin/css/custom.css"
	rel="stylesheet" type="text/css">
<link
	href="${request.getContextPath()}/Public/assets/global/plugins/bootstrap-datepicker/css/bootstrap-datepicker.min.css"
	rel="stylesheet" type="text/css">

<link
	href="${request.getContextPath()}/Public/assets/admin/css/common.css"
	rel="stylesheet" type="text/css">
<link
	href="${request.getContextPath()}/Public/assets/global/css/kkpager.css"
	rel="stylesheet" type="text/css">
<link rel="shortcut icon"
	href="${request.getContextPath()}/Public/favicon.ico">
<link href="${request.getContextPath()}/Public/css/client.css"
	rel="stylesheet" type="text/css">
<link href="${request.getContextPath()}/Public/css/customerDetail.css" rel="stylesheet" type="text/css">
</head>

<body class="page-header-top-fixed">
	<div id="div3"
		style="width: 100%; height: 100%; position: absolute; z-index: 10; opacity: 0.3; background-color: blue; display: none;"></div>
	<!--头部信息结束 -->
	<div class="page-header">
		<!--头部开始-->
		<#include "/include/top.html" />
		<!-- 头部信息结束 -->

		<!-- 头部菜单开始 -->
		<#include "/include/top_menu.html" />
		<!-- 头部菜单结束 -->
	</div>
	<!-- END HEADER -->



	<!-- BEGIN PAGE CONTAINER -->
	<div class="page-container">

		<!-- 内容开始 -->
		<div class="page-content">
			<div class="container-fluid">
				<!-- 当前位置提示结束 -->
				<!-- 当前位置提示开始 -->
				<ul class="page-breadcrumb breadcrumb">
					<li><a href="#">首页</a><i class="fa fa-circle"></i>
					<li class="active">客户管理<i class="fa fa-circle"></i>
					<li class="active">客户联系人<i class="fa fa-circle"></i>
					<li class="active">修改客户联系人</li>
				</ul>
				<div class="row margin-top-10">
					<div class="col-md-12">
						<div class="portlet light bordered">

							<form id="frm1">
								<div class="row">
									<h1>修改联系人</h1>
									<input type="hidden" name="id"
										value="${(contacter.id)?if_exists}">
									<table class="tb" cellspacing="1" border="1">
										<tr>
											<td class="tdTitle">姓名*</td>
											<td class="tdContent"><input type="text" name="name"
												id="name" value="${(contacter.name)?if_exists}"></td>
											<td class="tdTitle">性别*</td>
											<td class="tdContent"><label><input type="radio"
													name="sex" value="0"<#if contacter.sex?exists &&
													contacter.sex==0>checked</#if> />先生&nbsp;</label> <label><input
													type="radio" name="sex" value="1"<#if
													contacter.sex?exists && contacter.sex==1>checked</#if> />女士</label>
											</td>
										</tr>
										<tr>
											<td class="tdTitle">职位*</td>
											<td class="tdContent"><input type="text" name="position"
												maxlength="20" value="${(contacter.position)?if_exists}"
												id="position"></td>
											<td class="tdTitle">手机*</td>
											<td class="tdContent"><input type="text"
												id="mobilePhone" name="mobilePhone" maxlength="20"
												value="${(contacter.mobilePhone)?if_exists}"></td>
										</tr>
										<tr>
											<td class="tdTitle">QQ</td>
											<td class="tdContent"><input type="text" id="qq"
												name="qq" maxlength="20" value="${(contacter.qq)?if_exists}"
												onkeyup="this.value=this.value.replace(/\D/g,'')"
												onafterpaste="this.value=this.value.replace(/\D/g,'')"></td>
											<td class="tdTitle">固话</td>
											<td class="tdContent"><input type="text" id="telephone"
												name="telephone" maxlength="20"
												value="${(contacter.telephone)?if_exists}"></td>
										</tr>
										<tr>
											<td class="tdTitle">邮箱</td>
											<td class="tdContent"><input type="text" id="email"
												name="email" value="${(contacter.email)?if_exists}"></td>
											<td class="tdTitle">交易身份*</td>
											<td class="tdContent" id="identityType"><label><input
													type="checkbox" value="0"<#if
													contacter.tidentity?? && (contacter.tidentity ==
													0||contacter.tidentity==2)> checked </#if>/>采购</label> <label><input
													type="checkbox" value="1"<#if
													contacter.tidentity?? && (contacter.tidentity ==
													1||contacter.tidentity==2)> checked </#if>/>销售</label> <input
												type="hidden" id="tidentity"
												value="${contacter.tidentity?if_exists}" name="tidentity">
											</td>
										</tr>
										<tr>
											<td class="tdTitle">是否是关键人</td>
											<td class="tdContent"><input type="checkbox"
												name="keyPerson" value="1"<#if
												contacter?exists> <#if contacter.keyPerson?exists> <#if
												contacter.keyPerson==1> checked </#if> </#if> </#if> /></td>
											<td class="tdTitle"></td>
											<td class="tdContent"></td>
										</tr>
									</table>
									<div style="margin: 0 auto; width: 400px;">
										<div style="margin: 20px 0;">
											所属企业*&nbsp; <input type="text"
												value="<#if contacter.customer?exists>${contacter.customer.companyName?if_exists}</#if>"
												style="width: 150px;" readonly="readonly" id="companyinput"
												name="companyinputhi"
												onclick="showCustomerListView()"><br />
											<input type="hidden" value="${(contacter.customerId)!}"
												id="companyinputhi" name="customerId" />
										</div>
										<a class="btn green" onclick="contacterSave()"><i
											class="fa fa-save"></i> 保存</a>&nbsp; <span class="btn green"
											onclick="contacterAdd()"><i class="fa fa-plus"></i>
											保存并新建</span>&nbsp; <a class="btn green"
											onclick="window.history.back();">返回</a>

									</div>
								</div>
							</form>

						</div>
					</div>
				</div>
			</div>
		</div>
	</div>

	<!-- END PAGE CONTAINER -->


	<!-- 底部开始 -->
	<#include "/include/foot.html" />
	<!-- 底部结束 -->

	<!--[if lt IE 9]>
<script src="${request.getContextPath()}/Public/assets/global/plugins/respond.min.js"></script>
<script src="${request.getContextPath()}/Public/assets/global/plugins/excanvas.min.js"></script>
<![endif]-->
	<script
		src="${request.getContextPath()}/Public/assets/global/plugins/jquery.min.js"
		type="text/javascript"></script>
	<script
		src="${request.getContextPath()}/Public/assets/global/plugins/jquery-migrate.min.js"
		type="text/javascript"></script>
	<script
		src="${request.getContextPath()}/Public/assets/global/plugins/jquery-ui/jquery-ui.min.js"
		type="text/javascript"></script>
	<script
		src="${request.getContextPath()}/Public/assets/global/plugins/bootstrap/js/bootstrap.min.js"
		type="text/javascript"></script>
	<script
		src="${request.getContextPath()}/Public/assets/global/plugins/bootstrap-hover-dropdown/bootstrap-hover-dropdown.min.js"
		type="text/javascript"></script>
	<script
		src="${request.getContextPath()}/Public/assets/global/plugins/jquery-slimscroll/jquery.slimscroll.min.js"
		type="text/javascript"></script>
	<script
		src="${request.getContextPath()}/Public/assets/global/plugins/jquery.blockui.min.js"
		type="text/javascript"></script>
	<script
		src="${request.getContextPath()}/Public/assets/global/plugins/jquery.cokie.min.js"
		type="text/javascript"></script>
	<script
		src="${request.getContextPath()}/Public/assets/global/plugins/uniform/jquery.uniform.min.js"
		type="text/javascript"></script>
	<script
		src="${request.getContextPath()}/Public/assets/global/plugins/jquery.sparkline.min.js"
		type="text/javascript"></script>
	<script
		src="${request.getContextPath()}/Public/assets/global/plugins/bootstrap-datepicker/js/bootstrap-datepicker.js"
		type="text/javascript"></script>
	<script
		src="${request.getContextPath()}/Public/assets/global/scripts/metronic.js"
		type="text/javascript"></script>
	<script
		src="${request.getContextPath()}/Public/assets/admin/scripts/layout.js"
		type="text/javascript"></script>
	<script
		src="${request.getContextPath()}/Public/assets/global/plugins/kkpager.min.js"
		type="text/javascript"></script>
	<script
		src="${request.getContextPath()}/Public/assets/admin/scripts/indexComponent.js"
		type="text/javascript"></script>
	<script
		src="${request.getContextPath()}/Public/assets/admin/scripts/commonUtils.js"
		type="text/javascript"></script>

<script>
	function showCustomerListView(){
		CommonUtils.editModal('${request.getContextPath()}/contacter/showAllCustomerDialog.do','800');
	}

	$("#identityType :checkbox").each(function(index, element) {
		$(element).click(function() {
			var count = 0;
			$("#identityType :checkbox").each(function(index, element) {
				if ($(element).attr("checked")) {
					count++;
				}
			});
			if (count != 2) {
				$("#identityType :checkbox").each(function(index, element) {
					if ($(element).attr("checked")) {
						count = $(element).val();
					}
				});
			}
			$("#tidentity").val(count);
		});
	});

	function checkfrom() {
		var name = $("#name").val();
		var qq = $("#qq").val();
		var mobilePhone = $("#mobilePhone").val();
		var telephone = $("#telephone").val();
		var email = $("#email").val();
		var position = $("#position").val();
		var identityType = $("#identityType :checkbox:checked");
		var companyinput = $("#companyinput").val();

		if (position == "") {
			return "职位不能为空";
		}
		if (identityType.length <= 0) {
			return "请选择交易身份";
		}
		if (companyinput == "") {
			return "请选择所属企业";
		}

		if (name == null || name == "") {
			return "联系人姓名不能是空的呀！";
		}

		if (qq != null && qq != "") {
			if ((isNaN(qq))) {
				return "qq号是数字请填写数字！";
			}
		}
		if (mobilePhone.length == 0) {
			return '请输入联系人手机';
		} else {
			if (isNaN(mobilePhone)) {
				return '手机号码是数字亲~';
			}
			//匹配13，14，15，17,18开头的手机号码！
			var reg = /^0?1[3|4|5|7|8][0-9]\d{8}$/;
			if (!reg.test(mobilePhone)) {
				return '手机号码格式不正确!';
			}
		}

		if (email != null && email != "") {
			var re3 = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
			if (!re3.test(email)) {
				return "输入邮箱格式不正确";
			}
		}
		return true;
	}
	function cancel() {
		$("#div1").hide();
		$("#div3").hide();
	}

	function getSelected() {
		var companyid = $("input[name='companyids']:checked").val();
		$("#companyinput").val($("#" + companyid).html());
		$("#companyinputhi").val(companyid);
		cancel();
	}

	jQuery(document).ready(function() {

		Metronic.init(); // init metronic core componets
		Layout.init(); // init layout
		IndexComponent.init(); // init index component
	});
	recordDate();
	//初始化日期
	function recordDate() {
		var nowDate = new Date();
		//$('#date-picker').attr("date-date",nowDate.getFullYear()+"/"+parseInt(nowDate.getMonth()+1)+"/"+nowDate.getDate());
		$('.date-picker').datepicker({
			autoclose : true
		});
	}
	function reBack() {
		document.location.href = "${request.getContextPath()}/contacter/contacterList.do";
	}

	//联系人保存
	function contacterSave() {
		var aa = checkfrom();
		if (aa == true) {
			$.ajax({
				url : "${request.getContextPath()}/contacter/contacterSave.do",
				type : "post",
				dataType : "json",
				async : false,
				data : $("#frm1").serialize(),
				success : function(result) {
					if (result.code == "success") {
						CommonUtils.succModal2("系统提示", "修改成功！",
								document.referrer);
					} else {
						CommonUtils.succModal("系统提示",
								result.message);
					}
				}
			});
		} else {

			alert(aa);
		}
	}

	//联系人添加
	function contacterAdd() {

		var aa = checkfrom();
		if (aa == true) {
			$.ajax({
				url : "${request.getContextPath()}/contacter/contacterAdd.do",
				type : "post",
				dataType : "json",
				async : false,
				data : $("#frm1").serialize(),
				success : function(result) {
					if (result.code == "success") {
						CommonUtils.succModal("系统提示", "添加成功！");
						window.location = "${request.getContextPath()}/contacter/contacterList.do";
					} else {
						CommonUtils.succModal("警告", result.message);
					}
				}
			});
		} else {
			CommonUtils.succModal("验证", aa);
		}
	}
</script>

</body>
</html>